<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <link rel="stylesheet" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
<title>OPAC Web Service Unit Tests</title>
  <script>
  $(document).ready(function(){
    function checkISBN(data,checkValue) {
        var isbn = data.marc["020"][0].sf.a[0];
        var pos = isbn.indexOf(checkValue);
        equals(pos,0,"Veryifying ISBN " + checkValue); 
    }
    function checkTitle(data,checkValue) {
        var title = data.marc["245"][0].sf.a[0].toLowerCase();
        var pos = title.indexOf(checkValue)
        equals(pos,0,"Verifying title " + checkValue);
    }
    function checkOCLC(data,checkValue) {
        var oclc = data.marc["001"][0].sf.a[0];
        var pos = oclc.indexOf(checkValue);
        equals(pos,0,"Verifying OCLC " + checkValue);
    }

    var opactests = [{ edition: "vt", revision: "", catalogIndex: 0, check: [ 
        {method: checkISBN, searchString: "isbn", searchValue: "006073132X"},
        {method: checkTitle, searchString: "title", searchValue: "freakonomics"},
        {method: checkOCLC, searchString: "oclc", searchValue: "ocm57207630"}
        ] 
    },
    { edition: "vt", revision: 1, catalogIndex: 0, check: [
        {method: checkISBN, searchString: "isbn", searchValue: "006073132X"},
        {method: checkTitle, searchString: "title", searchValue: "freakonomics"},
        {method: checkOCLC, searchString: "oclc", searchValue: "ocm57207630"}
       ] 
    },
    { edition: "jmu", revision:1, catalogIndex: 0, check: [
        {method: checkISBN, searchString: "isbn", searchValue: "006073132X"},
        {method: checkTitle, searchString: "title", searchValue: "freakonomics"},
        {method: checkOCLC, searchString: "oclc", searchValue: "ocm57310900"}
        ] 
    },
    { edition: "E8D8B2C6", revision:"" , catalogIndex: 3, check: [ 
        {method: checkISBN, searchString: "isbn", searchValue: "006073132X"},
        {method: checkTitle, searchString: "title", searchValue: "freakonomics"}
        ]
    },
    { edition: "E8D8B2C6", revision:"3" , catalogIndex: 3, check: [
        {method: checkISBN, searchString: "isbn", searchValue: "006073132X"},
        {method: checkTitle, searchString: "title", searchValue: "freakonomics"}
        ] 
    }];

var url = "http://libx.lib.vt.edu/services/opac/"

for (var k = 0; k < opactests.length; k++) { 
for (var i = 0; i < opactests[k].check.length; i++) (function(k,i){
    var edition = opactests[k];
    var revision = "";
    if (edition.revision) {
        revision = ".";
    }
    module(edition.edition + revision + edition.revision);
    var check = edition.check[i];
    test("Checking " + check.searchString + " for value " + check.searchValue, function () {
         stop();
         $.getJSON(url + edition.edition + revision + edition.revision + "/" + edition.catalogIndex + "/"+ check.searchString +"/" + check.searchValue, function(data) {
                    check.method(data,check.searchValue);
                    //equals(0,0);
                    start();
                });

    });
})(k,i);
}

  });
  </script>
  
</head>
<body>
  <h1 id="qunit-header">OPAC Web Service Unit Tests</h1>
 <h2 id="qunit-banner"></h2>
 <h2 id="qunit-userAgent"></h2>
 <ol id="qunit-tests"></ol>
</body>
</html>
